package com.guo.anim.fallingstar;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

/**
 * 单圆弧的测试类
 */
public class SingleStarView extends View {
    private Paint fallingLinePaint;
    public SingleStarView(Context context) {
        super(context);
        initPaint();
    }

    public SingleStarView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initPaint();
    }

    public SingleStarView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initPaint();
    }
    /**
     * 初始化画笔
     */
    private void initPaint(){
        fallingLinePaint = new Paint();
        fallingLinePaint.setStrokeWidth(1);
        fallingLinePaint.setStyle(Paint.Style.STROKE);
        fallingLinePaint.setColor(0xFFE0E0E0);
        fallingLinePaint.setAntiAlias(true);
        setBackgroundColor(0x00E0E0E0);
    }

    RectF rect;
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int width = getMeasuredWidth();
        int height = getMeasuredHeight();
        rect = new RectF(width/4, height/4, width*3 / 4, height* 3 /4);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawArc(rect, 320, 60, false, fallingLinePaint);
    }
}
